package com.rongshu.view.userInfo.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class EditCollectedWorksActivity extends BaseActivity {
    @BindView(R.id.layout_back)
    LinearLayout layout_back;
    @BindView(R.id.txt_cancle)
    TextView txt_cancle;
    @BindView(R.id.txt_top_title)
    TextView txt_top_title;
    @BindView(R.id.txt_top_function)
    TextView txt_top_function;
    @BindView(R.id.edt_collected_works)
    EditText edt_collected_works;

    //intent
    private Intent intent = null;

    @Override
    protected int initLayout() {
        return R.layout.activity_edit_collected_works_view;
    }

    @Override
    protected void initView() {
        //top
        layout_back.setVisibility(View.GONE);
        txt_cancle.setVisibility(View.VISIBLE);
        txt_cancle.setText(R.string.cancle);
        txt_top_title.setText(R.string.edit_collected);
        txt_top_function.setVisibility(View.VISIBLE);
        txt_top_function.setText(R.string.complete);
        //文集名称
        intent = getIntent();
        if (intent != null) {
            edt_collected_works.setText(intent.getStringExtra(Constant.INTENT_TITLE));
            edt_collected_works.setSelection(edt_collected_works.getText().toString().length());
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }


    @OnClick({R.id.txt_cancle, R.id.txt_top_function})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.txt_cancle://取消
                finish();
                break;
            case R.id.txt_top_function://完成
                String edit_content = edt_collected_works.getText().toString().trim();
                if (TextUtils.isEmpty(edit_content)) {
                    toast(getString(R.string.please_input_collected_name));
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(Constant.INTENT_MESSAGE, edit_content);
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        //收回键盘
        showKeyboard(false);
    }
}
